import type { IAuthData } from '@/router/AuthLoader'
import useStore from '@/store'
import { Button } from 'antd'
import { useRouteLoaderData } from 'react-router-dom'

const AuthButton = (props: any) => {
  const { user } = useStore()
  const data = useRouteLoaderData('layout') as IAuthData
  if (!props.auth) {
    return <Button {...props}>{props.children}</Button>
  }
  if (data.buttonList.includes(props.auth) || user.role == 1) {
    return <Button {...props}>{props.children}</Button>
  }
  return <></>
}

export default AuthButton
